layui.use(['layer', 'form', 'admin', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var layer = layui.layer;

    /**
     * 检索店名
     */
    var languageAjax = new $ax(Feng.ctxPath + "/btyTxl/getDm");
    var languageResult = languageAjax.start();
    $.each(languageResult, function (index, val) {
        $("#ssctdm").append("<option value='" + val.id + "'>" + val.dm + "</option>");
    });
    form.render('select');

    form.on('select(ssctdm)', function (data) {
        var ssctdm = $("#ssctdm option:selected").text();
        if (ssctdm == "") {
            $("#ssctbh").html("");
            form.render('select');
        } else {
            var languageAjax = new $ax(Feng.ctxPath + "/btyTxl/getBh", function (data) {
            }, function (data) {
                $("#ssctbh").val(data.responseText);
            });
            languageAjax.set("dm", ssctdm);
            languageAjax.start();
            form.render('select');
        }
    });




    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/btyTxl/addfzr", function (data) {

            if (data == 1) {
                Feng.error("该手机号已存在，不允许重复添加！！");
                return false;
            }else {
                Feng.success("添加成功!");
                admin.putTempData('formOk', true);
                admin.closeThisDialog();
            }

        }, function (data) {
            Feng.error("添加失败!");
        });
        ajax.set(data.field);
        ajax.set("btyTxlId",$("#ssctdm").val());
        ajax.set("ssctdm", $("#ssctdm option:selected").text());
        ajax.start();
        //添加 return false 可成功跳转页面
        return false;
    });

});
